import com.hubu.map.HashMap;

import javax.swing.tree.TreeNode;

public class LinkedHashMap<K,V> extends HashMap<K,V> {

    private LinkedNode<K, V> first;
    private LinkedNode<K, V> last;

    private static class LinkedNode<K, V> extends HashMap.TreeNode<K, V> {
        LinkedNode<K, V> prev;
        LinkedNode<K, V> next;
        public LinkedNode(K key, V value, TreeNode<K, V> parent) {
            super(key,value,parent);
        }
    }

    @Override
    protected HashMap.TreeNode<K, V> createNode(K key, V value, HashMap.TreeNode<K, V> parent) {
        System.out.println("调用该方法");
        LinkedNode node = new LinkedNode(key, value, parent);
        if (first == null) {
            first = last = node;
        } else {
            last.next = node;
            node.prev = last;
            last = node;
        }
        return node;
    }
}
